package com.codeczx.videoviewdemo;

import android.content.Context;
import android.support.annotation.AttrRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by codeczx on 2017/8/15.
 */

public class MediaController extends FrameLayout {

    @BindView(R.id.iv_full_screen)
    ImageView ivFullScreen;
    @BindView(R.id.rl_media_controller)
    RelativeLayout rlMediaController;

    private Context mContext;
    private CzxVideoView.VideoController mController;

    public MediaController(Context context) {
        this(context, null);
    }

    public MediaController(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MediaController(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        initView();
    }

    private void initView() {
        View.inflate(mContext, R.layout.media_controller, this);
        ButterKnife.bind(this);
    }

    @OnClick(R.id.iv_full_screen)
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_full_screen:
                mController.changeViewSize();
        }
    }

    public void setVideoController(CzxVideoView.VideoController controller) {
        mController = controller;
    }

    private class ShowAndHideRunnable implements Runnable {

        @Override
        public void run() {
            if (rlMediaController.getVisibility()== View.VISIBLE) {
                rlMediaController.setVisibility(View.GONE);
            }
        }
    }
}
